<?php
namespace Home\Controller;
use Think\Controller;

class TouristController extends FrontController {
    protected function _initialize() {
        if (!session('用户')) {
            $this->success('请先登录!', U('User/login'));
        }
    }

    /**
     * 父类中已经有典型的CRUD操作并预留入口
     * 如有较大改动则覆盖一下
     */
    public function create() {
        //sui
        $this->assign('title', '新增游客');
        $sui = [
            'information' => 'active',
            'return' => true,
        ];
        $_POST['user_id'] = session('用户')['id'];
        $params['redirect'] = U('Tourist/list', ['fromType'=>$_SESSION['fromType'], 'fromId'=>$_SESSION['fromId']]);
        parent::create($params);
    }

    public function delete($id) {
        $params['redirect'] = U('Tourist/list', ['fromType'=>$_SESSION['fromType'], 'fromId'=>$_SESSION['fromId']]);
        parent::delete($id, $params);
    }

    public function update($id) {
        $params['redirect'] = U('Tourist/list', ['fromType'=>$_SESSION['fromType'], 'fromId'=>$_SESSION['fromId']]);
        parent::update($id, $params);
    }

    public function list($fromType = '', $fromId = '') {
        if (!session('用户')) {
            $this->redirect('login');
        }
        //sui
        $this->assign('title', '游客列表');
        $sui = [
            'information' => 'active',
            'return' => false,
        ];
        $this->assign('sui', $sui);
        if ($fromType != '') {
            $_SESSION['fromType'] = $fromType;
            $_SESSION['fromId'] = $fromId;
        } else {
            $_SESSION['fromType'] = '';
            $_SESSION['fromId'] = '';
        }
        $_GET['searchMap']['user_id'] = session('用户')['username'];
        parent::list();
    }

    public function detail($id = 0) {
        parent::detail($id);
    }

    public function import() {
        parent::import();
    }

    public function export() {
        parent::export();
    }
}
